using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class LosePanel : MonoBehaviour
{
	private LanguageController lang;

	private Text subTitle;

	private GameObject tooMuchImage;

	private GameObject tooSlowImage;

	private GameObject wrongLiquidImage;

	private GameObject panelWithAdButton;

	private GameObject panelWithoutAdButton;

	private Button adContinueButton;

//	private AdsController adsController;

	private Coroutine coroutineWaitForAd;

	private void Awake()
	{
		lang = LanguageController.instance;
		subTitle = base.transform.FindDeepChild("SubTitle_Text").GetComponent<Text>();
		tooMuchImage = base.transform.FindDeepChild("TooMuch_Image").gameObject;
		tooSlowImage = base.transform.FindDeepChild("TooSlow_Image").gameObject;
		wrongLiquidImage = base.transform.FindDeepChild("WrongLiquid_Image").gameObject;
		panelWithAdButton = base.transform.FindDeepChild("PanelWithAdButton").gameObject;
		panelWithoutAdButton = base.transform.FindDeepChild("PanelWithoutAdButton").gameObject;
		//adContinueButton = panelWithAdButton.transform.FindDeepChild("ContinueAd_Button").GetComponent<Button>();
		//adsController = UnityEngine.Object.FindObjectOfType<AdsController>();
	}

	private void Start()
	{
		GameEndPermissions.IncreaseCompletedGamesNumber();
		GameEndPermissions.ShowSpecialPanel(isWin: false);
	}

	public void OnShowEnd()
	{
	}

	public void OnEndHide()
	{
		AudioController.instance.UnPauseBackground();
		UnityEngine.Object.Destroy(base.gameObject);
	}

	public void SetReasonAndButtons(LoseReason reason, bool canUseContinueAd)
	{
		tooMuchImage.SetActive(value: false);
		tooSlowImage.SetActive(value: false);
		wrongLiquidImage.SetActive(value: false);
		switch (reason)
		{
		case LoseReason.TOO_MUCH:
			subTitle.text = lang.GetStringWithNewLinesAndSpaces("LosePanel_TooMuch");
			tooMuchImage.SetActive(value: true);
			break;
		case LoseReason.TOO_SLOW:
			subTitle.text = lang.GetStringWithNewLinesAndSpaces("LosePanel_TooSlow");
			tooSlowImage.SetActive(value: true);
			break;
		case LoseReason.WRONG_LIQUID:
			subTitle.text = lang.GetStringWithNewLinesAndSpaces("LosePanel_WrongLiquid");
			wrongLiquidImage.SetActive(value: true);
			break;
		case LoseReason.TOO_LITTLE:
			subTitle.text = lang.GetStringWithNewLinesAndSpaces("LosePanel_TooLittle");
			tooSlowImage.SetActive(value: true);
			break;
		case LoseReason.OVERFLOWED:
			subTitle.text = lang.GetStringWithNewLinesAndSpaces("LosePanel_Overflowed");
			tooMuchImage.SetActive(value: true);
			break;
		}
		panelWithAdButton.SetActive(value: false);
		panelWithoutAdButton.SetActive(value: false);
		if (canUseContinueAd)
		{
			panelWithAdButton.SetActive(value: true);
			//coroutineWaitForAd = StartCoroutine(IsAdReady());
		}
		else
		{
			panelWithoutAdButton.SetActive(value: true);
		}
	}

	//private IEnumerator IsAdReady()
	//{
	//	//if (!(adsController != null))
	//	//{
	//	//	yield break;
	//	//}
	//	WaitForSeconds wait = new WaitForSeconds(0.1f);
	//	while (true)
	//	{
	//		//if (adsController.IsInterstitialAdLoaded())
	//		//{
	//		//	adContinueButton.interactable = true;
	//		//}
	//		//else
	//		//{
	//		//	adContinueButton.interactable = false;
	//		//}
	//		yield return wait;
	//	}
	//}

	public void OnClickContinueAd()
	{
		AudioController.instance.Play("button");
		//StartCoroutine(ActionOnClickContinueAd());
	}

	//private IEnumerator ActionOnClickContinueAd()
	//{
	//	StopCoroutine(coroutineWaitForAd);
	//	adContinueButton.interactable = false;
	//	if (adsController.IsInterstitialAdLoaded())
	//	{
	//		adsController.ShowInterstitialAd();
	//		yield return new WaitForSeconds(0.1f);
	//	}
	//	GetComponent<Animator>().SetTrigger("Hide");
	//	Object.FindObjectOfType<GameController>().RestartCurrentDrink();
	//}

	public void OnClickRestart()
	{
		AudioController.instance.Play("button");
		GetComponent<Animator>().SetTrigger("Hide");
		Object.FindObjectOfType<GameController>().OnRestartLevel();
	}

	public void OnClickMenu()
	{
		AudioController.instance.Play("button");
		GetComponent<Animator>().SetTrigger("Hide");
		Object.FindObjectOfType<GameController>().BackToMainMenu(goToCurrentLevel: false);
	}
}
